package com.jinlejia.erp.ui.new_house.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jinlejia.erp.R;

import java.util.List;

/**
 * 横向城市选择
 */

public class HorizontalCityAdapter extends RecyclerView.Adapter<HorizontalCityAdapter.ViewHolder> {
    /**
     * ItemClick的回调接口
     * @author zhy
     *
     */
    public interface OnItemClickLitener {
        void onItemClick(String city, int position);
    }

    private OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    private LayoutInflater mInflater;
    private Context context;
    private List<String> data;

    public HorizontalCityAdapter(Context context, List<String> data) {
        mInflater = LayoutInflater.from(context);
        this.context = context;
        this.data = data;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_horizontal_city,parent,false);
        ViewHolder holder = new ViewHolder(view);
        holder.city = (TextView) holder.itemView.findViewById(R.id.id_history1);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.city.setText(data.get(position));
        holder.city.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOnItemClickLitener.onItemClick(data.get(position),position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    /**
     * 设置值
     */
    public static class ViewHolder extends RecyclerView.ViewHolder{
        public TextView city;
        public ViewHolder(View itemView) {
            super(itemView);
        }
    }
}
